<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="单据编码" prop="number">
        <el-input
          v-model="queryParams.number"
          placeholder="请输入单据编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户名称" prop="fcustomername">
        <el-input
          v-model="queryParams.fcustomername"
          placeholder="请输入客户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品编码" prop="fmaterialnumber">
        <el-input
          v-model="queryParams.fmaterialnumber"
          placeholder="请输入产品编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
        <span class="el-input__suffix">
                <span class="el-input__suffix-inner">
                  <i class="el-input_icon icon el-icon-search"
                     onmousemove="this.style.color='#366EDD'"
                     onmouseout="this.style.color='#919191'"
                     style="font-size: 16px;
                            position: absolute;
                            cursor: pointer;
                            right: 6px;
                            top: 10px;
                            background-color: #ffffff;"
                     @click="openF7('specialmaterial',false,true,null)"
                  />
                </span>
              </span>
      </el-form-item>
      <el-form-item label="产品名称" prop="fmaterialname">
        <el-input
          v-model="queryParams.fmaterialname"
          placeholder="请输入产品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-row></el-row>
<!--      <el-form-item label="规格" prop="fmodule">-->
<!--        <el-input-->
<!--          v-model="queryParams.fmodule"-->
<!--          placeholder="请输入规格"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="单位" prop="fheadquartersnumber">-->
<!--        <el-input-->
<!--          v-model="queryParams.fheadquartersnumber"-->
<!--          placeholder="请输入单位"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="提交部门" prop="fsubmitdept">
        <el-input
          v-model="queryParams.fsubmitdept"
          placeholder="请输入提交部门"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="cfstate">
        <el-select v-model="queryParams.cfstate" placeholder="请选择单据状态" clearable>
          <el-option
            v-for="dict in dict.type.bill_state"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
<!--      <el-form-item label="品类" prop="fcustomizedproducttype">-->
<!--        <el-select v-model="queryParams.fcustomizedproducttype" placeholder="请选择品类" clearable>-->
<!--          <el-option-->
<!--            v-for="dict in dict.type.bom_usercategory"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="dict.value"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
      <el-row></el-row>
      <el-form-item label="制单日期">
        <el-date-picker
          v-model="daterangeFcreatetime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['bomcostestimation/basebill:calcdemand:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          :disabled="single"
          @click="handleCopy"
          v-hasPermi="['bomcostestimation/basebill:calcdemand:add']"
        >复制
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['bomcostestimation/basebill:calcdemand:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['bomcostestimation/basebill:calcdemand:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['bomcostestimation/basebill:calcdemand:export']"
        >导出
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-dropdown class="avatar-container" trigger="click" :disabled="multiple">
          <div class="avatar-wrapper">
            <el-button
              type="primary"
              size="mini"
              plain
              :disabled="multiple"
              v-hasPermi="['bomcostestimation/basebill:calcdemand:aduit']"
            >
              审核/反审核
              <i class="el-icon-bottom"/>
            </el-button>
          </div>
          <el-dropdown-menu slot="dropdown" class="user-dropdown" divided>
            <a>
              <el-dropdown-item lot="dropdown" class="user-dropdown" @click.native="handleAudit">
                审核
              </el-dropdown-item>
            </a>
            <a>
              <el-dropdown-item lot="dropdown" class="user-dropdown" divided @click.native="handleNoAudit">
                反审核
              </el-dropdown-item>
            </a>
          </el-dropdown-menu>
        </el-dropdown>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          size="mini"
          plain
          @click="handleSubmit"
          :disabled="multiple"
          v-hasPermi="['bomcostestimation/basebill:calcdemand:submit']"
        >提交</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          @click="handlePush"
          v-hasPermi="['bomcostestimation/basebill:calcdemand:push']"
        >下推
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleCheckBelow"
          v-hasPermi="['bomcostestimation/basebill:calcdemand:checkBelow']"
        >下查
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="calcdemandList" @selection-change="handleSelectionChange"
              border
              max-height="800px"
              stripe>
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="单据编码" align="center" prop="number" width="180">
        <template slot-scope="scope">
          <span
            onMouseOver="this.style.color='#034769'"
            onMouseOut="this.style.color='#3cade5'"
            @click="handleUpdate(scope.row)"
            style="
            color: #3cade5;
            cursor: pointer;
            text-decoration:underline;
          ">{{ scope.row.number }}</span>
        </template>
      </el-table-column>
      <el-table-column label="产品编码" align="center" prop="fmaterialnumber"/>
      <el-table-column label="产品名称" align="center" prop="fmaterialname"/>
      <el-table-column label="规格" align="center" prop="fmodule"/>
      <el-table-column label="客户名称" align="center" prop="fcustomername"/>
      <el-table-column label="提交部门" align="center" prop="fsubmitdept"/>
<!--      <el-table-column label="部门编码" align="center" prop="fboxpackdetail"/>-->
<!--      <el-table-column label="部门id" align="center" prop="deptId"/>-->
      <el-table-column label="制单人" align="center" prop="fcreator"/>
      <el-table-column label="制单日期" align="center" prop="fcreatetime" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.fcreatetime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="cfstate"  >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.bill_state" :value="scope.row.cfstate"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="单位" align="center" prop="fheadquartersnumber"/>-->
      <el-table-column label="联系人" align="center" prop="fcontacts"/>
      <el-table-column label="联系电话" align="center" prop="fcontactnumber"/>
      <el-table-column label="时间类型" align="center" prop="cfseasontypeid" width="140">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.bom_seasontype" :value="scope.row.cfseasontypeid"/>
        </template>
      </el-table-column>
      <el-table-column label="基地" align="center" prop="cfwfzbaseid" width="140">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.bom_wfzbase" :value="scope.row.cfwfzbaseid"/>
        </template>
      </el-table-column>
      <el-table-column label="是否已下推" align="center" prop="ispush" width="140">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yes_no" :value="scope.row.ispush"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="基地出货日期" align="center" prop="fbaseshipmentdate" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.fbaseshipmentdate, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="定制产品类型" align="center" prop="fcustomizedproducttype" width="140">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.bom_customized_product_type" :value="scope.row.fcustomizedproducttype"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="操作" width="120" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['bomcostestimation/basebill:calcdemand:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['bomcostestimation/basebill:calcdemand:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改测试需求单维护对话框 -->
    <el-dialog v-drag :title="title" :visible.sync="open" width="1500px" v-dialog-drag-height append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="单据编码" prop="number">
              <el-input v-model="form.number" placeholder="请输入单据编码" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="客户编码" prop="fcustomernumber">
              <el-input v-model="form.fcustomernumber" placeholder="请输入客户编码"/>
              <span class="el-input__suffix">
                <span class="el-input__suffix-inner">
                  <i class="el-input_icon icon el-icon-search"
                     onmousemove="this.style.color='#366EDD'"
                     onmouseout="this.style.color='#919191'"
                     style="font-size: 16px;
                            position: absolute;
                            cursor: pointer;
                            right: 6px;
                            top: 8px;
                            background-color: #ffffff;"
                     @click="openF7('customer',false,null,false)"
                  />
                </span>
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="客户名称" prop="fcustomername">
              <el-input v-model="form.fcustomername" placeholder="请输入客户名称"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="产品编码" prop="fmaterialnumber">
              <el-input v-model="form.fmaterialnumber" @change="removeBillMaterial"  placeholder="请选择产品"/>
              <span class="el-input__suffix">
                <span class="el-input__suffix-inner">
                  <i class="el-input_icon icon el-icon-search"
                     onmousemove="this.style.color='#366EDD'"
                     onmouseout="this.style.color='#919191'"
                     style="font-size: 16px;
                            position: absolute;
                            cursor: pointer;
                            right: 6px;
                            top: 8px;
                            background-color: #ffffff;"
                     @click="openF7('specialmaterial',false,false,null)"
                  />
                </span>
            </span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="产品名称" prop="fmaterialname">
              <el-input v-model="form.fmaterialname" :disabled="form.fmaterialid!=null&&form.fmaterialid!=''" placeholder="请输入产品名称"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="规格" prop="fmodule" >
              <el-input v-model="form.fmodule"  placeholder="请输入规格"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="单位" prop="fheadquartersnumber">
              <el-input v-model="form.fheadquartersnumber"  placeholder="请输入单位"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="箱规" prop="boxgauge">
              <el-input v-model="form.boxgauge"  placeholder="请输入箱规"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="税率" prop="taxrate">
              <el-input v-model="form.taxrate"  placeholder="请输入税率"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="提交部门" prop="fsubmitdept">
              <el-input v-model="form.fsubmitdept" placeholder="请输入提交部门" readonly/>
              <span class="el-input__suffix">
                <span class="el-input__suffix-inner">
                  <i class="el-input_icon icon el-icon-search"
                     onmousemove="this.style.color='#366EDD'"
                     onmouseout="this.style.color='#919191'"
                     style="font-size: 16px;
                            position: absolute;
                            cursor: pointer;
                            right: 6px;
                            top: 8px;
                            background-color: #ffffff;"
                     @click="openF7('costcenter',false,false,null)"
                  />
                </span>
            </span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系人" prop="fcontacts">
              <el-input v-model="form.fcontacts" placeholder="请输入联系人"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系电话" prop="fcontactnumber">
              <el-input v-model="form.fcontactnumber" placeholder="请输入联系电话"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="时间类型" prop="cfseasontypeid">
              <el-select v-model="form.cfseasontypeid" placeholder="请选择时间类型" @change="changeSelection('seasontype')" style="width: 366.67px" clearable>
                <el-option
                  v-for="dict in dict.type.bom_seasontype"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="基地" prop="cfwfzbaseid">
              <el-select v-model="form.cfwfzbaseid" placeholder="请选择基地" @change="changeSelection('wfzbase')" style="width: 366.67px" clearable>
                <el-option
                  v-for="dict in dict.type.bom_wfzbase"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="制单日期" prop="fcreatetime" disabled>
              <el-date-picker clearable
                              v-model="form.fcreatetime"
                              type="date"
                              value-format="yyyy-MM-dd"
                              style="width: 366.67px"
                              placeholder="请选择制单日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="状态" prop="cfstate" >
              <el-select v-model="form.cfstate" placeholder="请选择单据状态" disabled style="width: 366.67px" readonly clearable>
                <el-option
                  v-for="dict in dict.type.bill_state"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="品类" prop="fcustomizedproducttype" >
              <el-select v-model="form.fcustomizedproducttype" placeholder="请选择品类" style="width: 366.67px" clearable>
                <el-option
                  v-for="dict in dict.type.bom_usercategory"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" placeholder="请选择备注"/>
            </el-form-item>
          </el-col>
<!--          <el-col span="8">-->
<!--            <el-form-item label="附件" prop="fisbarcode">-->
<!--              <FileUpload v-model="form.fisbarcode">附件</FileUpload>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
        </el-row>
        <el-divider content-position="center">测试需求单维护分录信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddBomCalcdemandentry">添加
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteBomCalcdemandentry">删除
            </el-button>
          </el-col>
        </el-row>
        <el-table border :data="bomCalcdemandentryList" :row-class-name="rowBomCalcdemandentryIndex"
                  @selection-change="handleBomCalcdemandentrySelectionChange" ref="bomCalcdemandentry">
          <el-table-column type="selection" width="50" align="center"/>
          <el-table-column label="序号" align="center" prop="index" width="50"/>
          <el-table-column label="类别" prop="cfcategory" width="150">
            <template slot-scope="scope">
              <el-select v-model="scope.row.cfcategory" placeholder="无" @change="switchDataSource(scope.row)" clearable>
                <el-option
                  v-for="dict in dict.type.bom_csxq_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="产品代码" prop="cfproductcode" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.cfproductcode" placeholder="请输入产品代码" :disabled="scope.row.cfcategory!='0'" :readonly="scope.row.cfcategory!='1'||scope.row.cfinternalcontrolcode=='1'" />
              <span class="el-input__suffix">
                <span class="el-input__suffix-inner">
                  <i class="el-input_icon icon el-icon-search"
                     onmousemove="this.style.color='#366EDD'"
                     onmouseout="this.style.color='#919191'"
                     style="font-size: 16px;
                            position: absolute;
                            cursor: pointer;
                            right: 6px;
                            top: 20px;
                            background-color: #ffffff;"
                     @click="openF7('specialmaterial',true,false,scope.row,true)"
                  />
                </span>
            </span>
            </template>
          </el-table-column>
          <el-table-column label="产品名称" prop="cfproductname" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.cfproductname" placeholder="请输入产品名称" :disabled="scope.row.cfcategory=='0'"/>
            </template>
          </el-table-column>
          <el-table-column label="产品单位" prop="cfproductunit" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.cfproductunit" placeholder="请输入产品单位"  :disabled="scope.row.cfcategory=='0'"/>
            </template>
          </el-table-column>
          <el-table-column label="规格" prop="cfboxcode" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.cfboxcode" placeholder="请输入规格"  :disabled="scope.row.cfcategory=='0'"/>
            </template>
          </el-table-column>
<!--          <el-table-column label="历史成本测算分录id" prop="cfboxgauge" width="150">-->
<!--            <template slot-scope="scope">-->
<!--              <el-input v-model="scope.row.cfboxgauge" placeholder="请输入产品单位"/>-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="长编码" prop="cfboxunit" width="450">-->
<!--            <template slot-scope="scope">-->
<!--              <el-input v-model="scope.row.cfboxunit" placeholder="请输入产品单位"/>-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="父编码" prop="cfboxname" width="180">-->
<!--            <template slot-scope="scope">-->
<!--              <el-input v-model="scope.row.cfboxname" placeholder="请输入产品单位"/>-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="单品箱规" prop="cfsingleboxgauge" width="150">-->
<!--            <template slot-scope="scope">-->
<!--              <el-input v-model="scope.row.cfsingleboxgauge" placeholder="请输入单品箱规"  :disabled="scope.row.cfcategory=='0'"/>-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="折只数" prop="cffoldnumber" width="150">-->
<!--            <template slot-scope="scope">-->
<!--              <el-input v-model="scope.row.cffoldnumber" placeholder="请输入折只数"  :disabled="scope.row.cfcategory=='0'" @change="sumListAmount(scope.row)"/>-->
<!--            </template>-->
<!--          </el-table-column>-->
          <el-table-column label="内配数量" prop="cfquotecount" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.cfquotecount" onkeyup="this.value=this.value.match(/\d+\.?\d{0,12}/);" placeholder="请输入内配数量" @change="sumListAmount(scope.row)"/>
            </template>
          </el-table-column>
<!--          <el-table-column label="总只数" prop="cftotalcount" width="150">-->
<!--            <template slot-scope="scope">-->
<!--              <el-input v-model="scope.row.cftotalcount" placeholder="请输入总只数" disabled/>-->
<!--            </template>-->
<!--          </el-table-column>-->
          <el-table-column label="备注" prop="remark" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.remark" placeholder="请输入备注"/>
            </template>
          </el-table-column>
          <el-table-column label="合计材料成本" v-if="false" prop="cftotalmaterialcost" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.cftotalmaterialcost" placeholder="请输入合计材料成本" disabled/>
            </template>
          </el-table-column>
          <el-table-column label="合计成本" v-if="false" prop="cftotalcost" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.cftotalcost" placeholder="请输入合计成本" disabled/>
            </template>
          </el-table-column>
          <el-table-column label="含税成本" v-if="false" prop="cftaxcost" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.cftaxcost" placeholder="请输入含税成本" disabled/>
            </template>
          </el-table-column>
          <el-table-column label="包装成本" v-if="false" prop="cfpackcost" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.cfpackcost" placeholder="请输入包装成本" disabled/>
            </template>
          </el-table-column>
          <el-table-column label="变动费用" v-if="false" prop="cfalterationfee" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.cfalterationfee" placeholder="请输入变动费用" disabled/>
            </template>
          </el-table-column>
          <el-table-column label="固定费用" v-if="false" prop="cffixedfee" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.cffixedfee" placeholder="请输入固定费用" disabled/>
            </template>
          </el-table-column>

        </el-table>
        <el-divider content-position="center" v-if="false">合计行</el-divider>
        <el-table v-if="false" :data="bomCalcdemandentryListSumAmount" ref="bomCalcdemandentrySum">
          <el-table-column label="合计材料成本" prop="cftotalmaterialcost" width="150">
          </el-table-column>
          <el-table-column label="合计成本" prop="cftotalcost" width="150">
          </el-table-column>
          <el-table-column label="含税成本" prop="cftaxcost" width="150">
          </el-table-column>
          <el-table-column label="包装成本" prop="cfpackcost" width="150">
          </el-table-column>
          <el-table-column label="变动费用" prop="cfalterationfee" width="150">
          </el-table-column>
          <el-table-column label="固定费用" prop="cffixedfee" width="150">
          </el-table-column>
          <el-table-column label="" prop="cffixedfee" style="width: 1px">
            <template slot-scope="scope" style="width: 1px">
              <el-input v-model="scope.row.cffixedfee" STYLE="width:1px;visibility: hidden"/>
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" :disabled="this.form.cfstate!='SAVE'">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <base-data-view @emitToParent="getF7Data" :tobasedata.sync='basedatadialog'></base-data-view>
    <base-data-view @emitToParent="getF7Data" :bomCostcalc.sync='basedatadialog'></base-data-view>
  </div>
</template>

<script>
import {listCalcdemand, getCalcdemand, delCalcdemand, addCalcdemand, updateCalcdemand, pushCostCalc,checkBelow,optionStatus} from "@/api/bomcostestimation/basebill/calcdemand";
import baseDataView from "@/views/bomcostestimation/f7View/baseDataView";
import {delCostcalc, getCostcalc, getMaterialBomAllNodes} from "@/api/bomcostestimation/basebill/costcalc";
import { listMaterialhalf, getMaterialhalf, delMaterialhalf, addMaterialhalf, updateMaterialhalf } from "@/api/bomcostestimation/basedocument/materialhalf";
import {listAsscategory} from "@/api/bomcostestimation/basedocument/asscategory";

export default {
  name: "Calcdemand",
  dicts: ['bom_customized_product_type','bom_csxq_type','bom_wfzbase','bom_seasontype','bom_plant','yes_no','bill_state','bom_usercategory'],
  components: {baseDataView},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      numbers: [],
      ispush: [],
      states: [],
      // 子表选中数据
      checkedBomCalcdemandentry: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 测试需求单维护表格数据
      calcdemandList: [],
      // 测试需求单维护分录表格数据
      bomCalcdemandentryList: [],
      //合计行
      bomCalcdemandentryListSumAmount: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      daterangeFcreatetime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        number: null,
        fmodule: null,
        fmaterialname: null,
        fmaterialnumber: null,
        fcustomernumber: null,
        fcustomername: null,
        fheadquartersnumber: null,
        boxgauge: null,
        taxrate: null,
        fsubmitdept: null,
        fbaseshipmentdate: null,
        fcustomizedproducttype: null,
        fcreatetime: null,
        cfstate: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        taxrate: [
          { required: true, message: "税率为空", trigger: "blur" }
        ],
        fmodule: [
          { required: true, message: "规格为空", trigger: "blur" }
        ],
        boxgauge: [
          { required: true, message: "箱规为空", trigger: "blur" }
        ],
        fheadquartersnumber: [
          { required: true, message: "单位为空", trigger: "blur" }
        ],
        fsubmitdept: [
          { required: true, message: "提交部门为空", trigger: "blur" }
        ],
        cfseasontypeid: [
          { required: true, message: "时间类型为空", trigger: "blur" }
        ],
        cfwfzbaseid: [
          { required: true, message: "基地不能为空", trigger: "blur" }
        ],
        fcustomizedproducttype: [
          { required: true, message: "品类不能为空", trigger: "blur" }
        ],
      },
      // 定制化类型
      types: [],
      //定制产品类型数组
      // customizedproducttypes:["A:库外内容物，库内包装","B:库内内容物，库外包装","C:库内内容物，库内包装","D:库外内容物，车内包务"]
      basedatadialog: {
        //定义一个参数用来判断当前是获取什么类型的数据
        f7dataType: null,
        costcalc: {
          show: false,
          index: null,
          row: null,
          data: null,
          isEntry: true,
        },
        customer: {
          show: false,
        },
        costcenter: {
          show: false,
        },
        specialmaterial: {
          //是否显示特殊物料数据对话框
          show: false,
          //弹出的特殊物料是否用于查询
          isSearch: false,
          index: null,
          row: null,
          isEntry: false,
          list:[],
        },
        costcalclist: {
          show: false,
          index:null,
          row:null,
          isEntry:false,
          list:[],
          queryParams:{
            pageNum: 1,
            pageSize: 10,
            materialbomname: null,
            materialbomnumber: null,
            materialbomid: null,
            ffivouchered: "1",
          }
        },
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询测试需求单维护列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeFcreatetime && '' != this.daterangeFcreatetime) {
        this.queryParams.params["beginFcreatetime"] = this.daterangeFcreatetime[0];
        this.queryParams.params["endFcreatetime"] = this.daterangeFcreatetime[1];
      }
      listCalcdemand(this.queryParams).then(response => {
        this.calcdemandList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },

    // 表单重置
    reset() {
      this.form = {
        fid: null,
        fcreator: this.$store.state.user.name,
        fcreatetime: new Date(),
        flastupdateuserid: null,
        flastupdatetime: null,
        number: null,
        fmodule: null,
        fcustomernumber: null,
        fcustomername: null,
        fheadquartersnumber: null,
        boxgauge: null,
        taxrate: null,
        fmaterialid: null,
        fmaterialnumber: null,
        fmaterialname: null,
        fcontacts: null,
        fcontactnumber: null,
        fsubmitdept: null,
        fbaseshipmentdate: null,
        fisaproductwithinthedom: null,
        fproductiondate: null,
        fcustomizedproducttype: null,
        fisbarcode: null,
        fisqualityreport: null,
        fismaterialraw: null,
        cfstate: null,
        cfseasontypeid: null,
        cfwfzbaseid: null,
        remark: null,
        fboxpackdetail: null
      };
      this.bomCalcdemandentryList = [];
      this.bomCalcdemandentryListSumAmount = [];
      this.handleAddBomCalcdemandentry();
      let obj = {};
      obj.cftotalmaterialcost = "";
      obj.cftotalcost = "";
      obj.cftaxcost = "";
      obj.cfpackcost = "";
      obj.cfalterationfee = "";
      obj.cffixedfee = "";
      this.bomCalcdemandentryListSumAmount.push(obj);
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeFcreatetime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.fid)
      this.numbers = selection.map(item => item.number)
      this.ispush = selection.map(item => item.ispush)
      this.single = selection.length !== 1
      this.multiple = !selection.length
      this.pushCostCalcData = selection
      this.states = selection.map(item => item.cfstate)
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      if(this.$store.state.user.dept.deptName){
        this.form.fsubmitdept = this.$store.state.user.dept.deptName;
        this.form.fboxpackdetail = this.$store.state.user.dept.deptNumber;
      }
      this.open = true;
      this.title = "添加测试需求单";
      this.form.cfstate="SAVE";
    },
    /** 复制按钮操作 */
    handleCopy(row) {
      this.reset();
      const id = this.ids
      getCalcdemand(id).then(response => {
        this.form = response.data;
        this.form.fid = null;
        this.form.fcreator = this.$store.state.user.name;
        this.form.number = null;
        this.form.cfstate = "SAVE";
        this.form.fcreatetime = new Date();
        this.form.ispush = "0";
        this.bomCalcdemandentryList = response.data.bomCalcdemandentryList;
        this.open = true;
        this.title = "添加测试需求单";
        this.sumListAmount();
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const fid = row.fid || this.ids
      getCalcdemand(fid).then(response => {
        this.form = response.data;
        this.bomCalcdemandentryList = response.data.bomCalcdemandentryList;
        this.sumListAmount();
        this.open = true;
        this.title = "修改测试需求单维护";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          let bomCalcdemandentryList = this.bomCalcdemandentryList;
          for (let lengthKey in bomCalcdemandentryList) {
            let regExpMatchArray = (bomCalcdemandentryList[lengthKey].cfquotecount+"a").match(/\d+\.?\d{0,12}/);
            if(regExpMatchArray==null||regExpMatchArray==undefined||regExpMatchArray.length==0){
              this.$modal.msgError("内配数量必填且不能为0");
              return;
            }
            let cfquotecount = regExpMatchArray[0]
            if(!cfquotecount||(cfquotecount-0 <= 0)){
              this.$modal.msgError("内配数量必填且不能为0");
              return;
            }
            bomCalcdemandentryList[lengthKey].cfquotecount = cfquotecount;
            if (bomCalcdemandentryList[lengthKey].cfcategory != '0') {
              if (!(bomCalcdemandentryList[lengthKey].cfboxcode != undefined && bomCalcdemandentryList[lengthKey].cfboxcode != null && bomCalcdemandentryList[lengthKey].cfboxcode.length > 0)) {
                this.$modal.msgError("非库内商品的分录规格必填");
                return;
              }
              if (!(bomCalcdemandentryList[lengthKey].cfproductunit != undefined && bomCalcdemandentryList[lengthKey].cfproductunit != null && bomCalcdemandentryList[lengthKey].cfproductunit.length > 0)) {
                this.$modal.msgError("非库内商品的分录单位必填");
                return;
              }
            }
          }
          this.form.bomCalcdemandentryList = bomCalcdemandentryList;
          if (this.form.fid != null) {
            updateCalcdemand(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCalcdemand(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      let id = row.fid || this.ids;
      const ids = [];
      let billnos = row.number || this.numbers;
      let numbers = [];
      let state = row.cfstate || this.states;
      if (state == null || state.length === 0) {
        this.$modal.msgError("请选择单据");
        return;
      }
      if(!Array.isArray(id)){
        id = [id];
      }
      if(!Array.isArray(billnos)){
        billnos = [billnos];
      }
      if(!Array.isArray(state)){
        state = [state];
      }
      for (let i = 0; i < state.length; i++) {
        if (state[i] === "SAVE") {
          ids.push(id[i])
        }else{
          numbers.push(billnos[i])
        }
      }
      if (numbers.length === id.length) {
        this.$modal.msgError("选中的单据不符合操作");
        return;
      }
      this.$modal.confirm('是否确认删除测试需求单维护编号为"' + billnos + '"的数据项？').then(function() {
        return delCalcdemand(ids);
      }).then(() => {
        this.getList();
        if (numbers.length === 0) {
          this.$modal.msgSuccess("删除成功");
        } else {
          this.$modal.msgError("存在单据:" + numbers + ",不是暂存状态,无法删除,其余单据已删除");
        }
      }).catch(() => {});
    },
    /** 单据审核*/
    handleAudit(row) {
      const id = row.fid || this.ids;
      const ids = [];
      const billnos = row.number || this.numbers;
      const fstate = "AUDIT"; //审核状态
      let numbers = [];
      let state = this.states;
      if (state == null || state.length === 0) {
        this.$modal.msgError("请选择单据");
        return;
      }
      for (let i = 0; i < state.length; i++) {
        if (state[i] === "SUBMIT") {
          ids.push(id[i])
        } else {
          numbers.push(billnos[i])
        }
      }
      if (numbers.length === id.length) {
        this.$modal.msgError("选中的单据不符合操作");
        return;
      }
      optionStatus(ids, fstate).then(response => {
        this.getList(); //刷新状态
        if (numbers.length === 0) {
          this.$modal.msgSuccess("已执行审核操作");
        } else {
          this.$modal.msgError("存在单据:" + numbers + ",不是暂存状态,无法审核,其余单据已审核");
        }
      });
    },
    /** 单据提交*/
    handleSubmit(row) {
      const id = row.fid || this.ids;
      const ids = [];
      const billnos = row.number || this.numbers;
      const fstate = "SUBMIT"; //提交状态
      let numbers = [];
      let state = this.states;
      if (state == null || state.length === 0) {
        this.$modal.msgError("请选择单据");
        return;
      }
      for (let i = 0; i < state.length; i++) {
        if (state[i] === "SAVE") {
          ids.push(id[i])
        } else {
          numbers.push(billnos[i])
        }
      }
      if (numbers.length === id.length) {
        this.$modal.msgError("选中的单据不符合操作");
        return;
      }
      optionStatus(ids, fstate).then(response => {
        this.getList(); //刷新状态
        if (numbers.length === 0) {
          let data = response.data;
          if(data==ids.length){
            this.$modal.msgSuccess("已执行提交操作");
          }else if(data==0){
            this.$modal.msgError("选中的单据不符合操作");
          }else{
            this.$modal.msgWarning("已执行提交操作,但有"+(ids.length-data)+"条数据提交失败,失败原因可能是分录为空");
          }
        } else {
          let data = response.data;
          if(data==ids.length){
            this.$modal.msgError("存在单据:" + numbers + ",不是暂存状态,无法提交,其余单据已提交");
          }else if(data==0){
            this.$modal.msgError("选中的单据不符合操作");
          }else{
            this.$modal.msgWarning("存在单据:" + numbers + ",不是暂存状态,无法提交,其余单据已执行提交操作,但有"+(ids.length-data)+"条数据提交失败,失败原因可能是分录为空");
          }
        }
      });
    },
    /** 单据反审核*/
    handleNoAudit(row) {
      const id = this.ids;
      const ids = [];
      const billnos = this.numbers;
      const fstate = "SAVE"; //暂存状态
      var numbers = [];
      var state = this.states;
      if (state == null || state.length === 0) {
        this.$modal.msgError("请选择单据");
        return;
      }
      for (let i = 0; i < state.length; i++) {
        if (state[i] === "AUDIT") {
          ids.push(id[i])
        } else {
          numbers.push(billnos[i])
        }
      }
      if (numbers.length === id.length) {
        this.$modal.msgError("选中的单据不符合操作");
        return;
      }
      optionStatus(ids, fstate).then(response => {
        this.getList(); //刷新状态
        if (numbers.length === 0) {
          this.$modal.msgSuccess("已执行反审核操作(存在下游单据的需求单无法反审核)");
        } else {
          this.$modal.msgError("存在单据:" + numbers + ",不是审核状态,无法反审核,其余单据已反审核");
        }
      });
    },
    /** 下推到成本测算按钮操作 */
    handlePush(row) {
      const fids = row.fid || this.ids;
      const ids = [];
      let billnos = [];
      const numbers = row.number || this.numbers;
      const state = this.states;
      if (fids.length < 1 && this.pushCostCalcData.length < 20) {
        this.$modal.msgError("请选择需要下推的数据");
        return;
      }
      for (let i = 0; i < state.length; i++) {
        if (state[i] === "AUDIT") {
          ids.push(fids[i])
        } else {
          billnos.push(numbers[i])
        }
      }
      if (billnos.length === fids.length) {
        this.$modal.msgError("选中的单据不符合操作");
        return;
      }
      let that = this;
      this.$modal.confirm('是否确认下推至成本测算为"' + numbers + '"的数据项？').then(function () {
        that.loading = true;
        pushCostCalc(fids).then(() => {
          that.$modal.msgSuccess("下推成功");
          that.getList();
        }).catch(() => {
          that.$modal.msgError("下推失败");
          that.getList();
        });
      })
    },
    /** 下查按钮操作 */
    handleCheckBelow(row) {
      const fids = row.fid || this.ids;
      var fid = fids[0]
      checkBelow(fid).then(response => {
        if(response.data!=undefined){
          this.basedatadialog.costcalc.show = false;
          this.basedatadialog.f7dataType = "costcalc";
          this.basedatadialog.costcalc.show = true;
          this.basedatadialog.costcalc.data = response.data;
        }else{
          this.$modal.msgError("不存在下游单据");
        }
      }).catch(() => {
      });
    },
    /** 测试需求单维护分录序号 */
    rowBomCalcdemandentryIndex({row, rowIndex}) {
      row.index = rowIndex + 1;
    },
    /** 测试需求单维护分录添加按钮操作 */
    handleAddBomCalcdemandentry() {
      this.bomCalcdemandentryList.push(this.creatNewEntry());
      this.sumListAmount();
    },
    creatNewEntry(){
      let obj = {};
      obj.cfcategory = "0";
      obj.cfinternalcontrolcode = "";
      obj.cfproductcode = "";
      obj.cfproductname = "";
      obj.cfproductunit = "";
      obj.cfsingleboxgauge = "";
      obj.cfperbagweight = "";
      obj.cftotalweight = "";
      obj.cfboxnumber = "";
      obj.cfassbagnumber = "";
      obj.cftotalcount = "";
      obj.remark = "";
      obj.cfquotecount = "";
      obj.cffoldnumber = "";
      obj.cfboxcode = "";
      obj.cfboxname = "";
      obj.cfboxunit = new Date().getTime();
      obj.cfboxgauge = "";
      obj.cfboxamount = "";
      obj.cftotalmaterialcost = "";
      obj.cftotalcost = "";
      obj.cftaxcost = "";
      obj.cfpackcost = "";
      obj.cfalterationfee = "";
      obj.cffixedfee = "";
      return obj;
    },
    /** 测试需求单维护分录删除按钮操作 */
    handleDeleteBomCalcdemandentry() {
      if (this.checkedBomCalcdemandentry.length == 0) {
        this.$modal.msgError("请先选择要删除的测试需求单维护分录数据");
      } else {
        const bomCalcdemandentryList = this.bomCalcdemandentryList;
        const checkedBomCalcdemandentry = this.checkedBomCalcdemandentry;
        this.bomCalcdemandentryList = bomCalcdemandentryList.filter(function (item) {
          return checkedBomCalcdemandentry.indexOf(item.index) == -1
        });
        this.sumListAmount();
      }
    },
    /** 复选框选中数据 */
    handleBomCalcdemandentrySelectionChange(selection) {
      this.checkedBomCalcdemandentry = selection.map(item => item.index)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('bomcostestimation/basebill/calcdemand/export', {
        ...this.queryParams
      }, `calcdemand_${new Date().getTime()}.xlsx`)
    },
    switchDataSource(obj){
      obj.cfinternalcontrolcode = "";
      obj.cfproductcode = "";
      obj.cfproductname = "";
      obj.cfproductunit = "";
      obj.cfsingleboxgauge = "";
      obj.cfperbagweight = "";
      obj.cftotalweight = "";
      obj.cfboxnumber = "";
      obj.cfassbagnumber = "";
      obj.cftotalcount = "";
      obj.remark = "";
      obj.cfquotecount = "";
      obj.cffoldnumber = "";
      obj.cfboxcode = "";
      obj.cfboxname = "";
      obj.cfboxgauge = "";
      obj.cfboxamount = "";
      obj.cftotalmaterialcost = "";
      obj.cftotalcost = "";
      obj.cftaxcost = "";
      obj.cfpackcost = "";
      obj.cfalterationfee = "";
      obj.cffixedfee = "";
      this.sumListAmount();
    },
    /** 计算合计行 */
    sumListAmount(){
      let bomCalcdemandentryList = this.bomCalcdemandentryList;
      let obj = {};
      obj.cftotalmaterialcost = 0;
      obj.cftotalcost = 0;
      obj.cftaxcost = 0;
      obj.cfpackcost = 0;
      obj.cfalterationfee = 0;
      obj.cffixedfee = 0;
      for (let i = 0; i < bomCalcdemandentryList.length; i++) {
        let listElement = bomCalcdemandentryList[i];
        if(listElement.cfcategory=="0"){
          obj.cftotalmaterialcost += (listElement.cftotalmaterialcost-0);
          obj.cftotalcost += (listElement.cftotalcost-0);
          obj.cftaxcost += (listElement.cftaxcost-0);
          obj.cfpackcost += (listElement.cfpackcost-0);
          obj.cfalterationfee += (listElement.cfalterationfee-0);
          obj.cffixedfee += (listElement.cffixedfee-0);
        }
        listElement.cftotalcount = (listElement.cffoldnumber-0)*(listElement.cfquotecount-0);
      }
      this.bomCalcdemandentryListSumAmount = [];
      this.bomCalcdemandentryListSumAmount.push(obj)
    },
    changeSelection(type){
      if(type=="wfzbase"){
        this.$refs["form"].validateField("cfwfzbaseid");
      }else{
        this.$refs["form"].validateField("cfseasontypeid");
      }
    },
    removeBillMaterial(){
      this.form.fmaterialid = null;
      this.form.fmaterialname = null;
      this.form.taxrate = null;
      this.form.fmodule = null;
      this.form.fheadquartersnumber = null;
      this.form.boxgauge = null;
    },
    /** f7点击事件 */
    openF7(show, isEntry, isSearch, row) {
      this.basedatadialog.F7dataType = show;
      switch (show) {
        case 'costcenter':
          this.basedatadialog.costcenter.show = !this.basedatadialog.costcenter.show;
          break;
        case 'customer':
          this.basedatadialog.customer.show = !this.basedatadialog.customer.show;
          break;
        case 'specialmaterial':
          if (isEntry) {
            this.basedatadialog.specialmaterial.row = row;
            this.basedatadialog.specialmaterial.isEntry = true;
            if(row.cfcategory=="0"){
              this.basedatadialog.F7dataType = "costcalclist";
              this.basedatadialog.costcalclist.row = row;
              this.basedatadialog.costcalclist.show = !this.basedatadialog.costcalclist.show;
              break;
            }else if(row.cfcategory!="0"){
              return
            }
          } else if (isSearch) {
            this.basedatadialog.specialmaterial.isSearch = true
          }
          this.basedatadialog.specialmaterial.show = !this.basedatadialog.specialmaterial.show;
          break;
      }
    },
    /** f7获取值 */
    getF7Data(data) {
      switch (this.basedatadialog.F7dataType) {
        case "costcenter":
          if (data.costcenter != null) {
            this.form.fsubmitdept = data.costcenter.name;
            this.form.fboxpackdetail = data.costcenter.number;
          }else{
            this.form.fsubmitdept = null;
            this.form.fboxpackdetail = null;
          }
          this.$refs["form"].validateField("fsubmitdept");
          break;
        case "customer":
          if (data.customer != null) {
            this.form.fcustomername = data.customer.customername;
            this.form.fcustomernumber = data.customer.customernumber;
          }else{
            this.form.fcustomername = null;
            this.form.fcustomernumber = null;
          }
          break;
        case "specialmaterial":
          if (this.basedatadialog.specialmaterial.isSearch) {
            if (data.specialmaterial != null) {
              //查询
              this.queryParams.fmaterialnumber  =data.specialmaterial.materialnumber
              this.basedatadialog.specialmaterial.isSearch = false
            }else{
              this.queryParams.fmaterialnumber  = null
              this.basedatadialog.specialmaterial.isSearch = false
            }
          }
          else if (this.basedatadialog.specialmaterial.isEntry) {
            if (data.specialmaterial != null) {
              //分录
              this.basedatadialog.specialmaterial.row.cfinternalcontrolcode ="1"
              this.basedatadialog.specialmaterial.row.cfproductcode =data.specialmaterial.materialnumber
              this.basedatadialog.specialmaterial.row.cfproductname =data.specialmaterial.materialname
              this.basedatadialog.specialmaterial.row.cfproductunit = data.specialmaterial.baseunitname
              this.basedatadialog.specialmaterial.row.cfsingleboxgauge = data.specialmaterial.boxspecification
              let qtytoegg = data.specialmaterial.qtytoegg;
              let qtytodumpling = data.specialmaterial.qtytodumpling;
              let qtytocake = data.specialmaterial.qtytocake;
              if(qtytoegg!=undefined&&qtytoegg-0!=0){
                this.basedatadialog.specialmaterial.row.cffoldnumber = qtytoegg
              }else if(qtytodumpling!=undefined&&qtytodumpling-0!=0){
                this.basedatadialog.specialmaterial.row.cffoldnumber = qtytodumpling
              }else if(qtytocake!=undefined&&qtytocake-0!=0){
                this.basedatadialog.specialmaterial.row.cffoldnumber = qtytocake
              }
              this.basedatadialog.specialmaterial.isEntry = false
              this.basedatadialog.specialmaterial.row.cftotalmaterialcost = 0;
              this.basedatadialog.specialmaterial.row.cftotalcost = 0;
              this.basedatadialog.specialmaterial.row.cftaxcost = 0;
              this.basedatadialog.specialmaterial.row.cfpackcost = 0;
              this.basedatadialog.specialmaterial.row.cfalterationfee = 0;
              this.basedatadialog.specialmaterial.row.cffixedfee = 0;
              this.sumListAmount();
              // this.categoryChange(this.basedatadialog.specialmaterial.row)
            }else{
              this.switchDataSource(this.basedatadialog.specialmaterial.row);
            }
          }
          else {
            if (data.specialmaterial != null) {
              //表头
              this.form.fmaterialid = "1";
              this.form.fmaterialnumber = data.specialmaterial.materialnumber;
              this.form.fmaterialname = data.specialmaterial.materialname;
              this.form.fmodule = data.specialmaterial.specifications;
              this.form.taxrate = data.specialmaterial.taxrate;
              this.form.boxgauge = data.specialmaterial.boxspecification;
              this.form.fheadquartersnumber = data.specialmaterial.baseunitname;
            }else{
              this.form.fmaterialnumber = null;
              this.removeBillMaterial();
            }
            this.$refs["form"].validateField("boxgauge");
            this.$refs["form"].validateField("fheadquartersnumber");
            this.$refs["form"].validateField("fmodule");
            this.$refs["form"].validateField("taxrate");
          }
          break;
        case "costcalclist":
          if (data.costcalclist != null) {
            this.basedatadialog.costcalclist.row.cfproductcode = data.costcalclist.cfmaterialid;
            this.basedatadialog.costcalclist.row.cfproductname = data.costcalclist.cfmaterialname;
            this.basedatadialog.costcalclist.row.cfproductunit = data.costcalclist.cfbaseunit;
            this.basedatadialog.costcalclist.row.cfboxcode = data.costcalclist.cfmodel;
            this.basedatadialog.costcalclist.row.cfboxamount = "1";
            this.basedatadialog.costcalclist.row.cfboxname = "";
            this.basedatadialog.costcalclist.row.cfboxgauge = data.costcalclist.fid;
            this.basedatadialog.costcalclist.row.cftotalmaterialcost = data.costcalclist.cftotalmaterialcost;
            this.basedatadialog.costcalclist.row.cftotalcost = data.costcalclist.cftotalcost;
            this.basedatadialog.costcalclist.row.cftaxcost = data.costcalclist.cftaxcost;
            this.basedatadialog.costcalclist.row.cfpackcost = data.costcalclist.cfpackcost;
            this.basedatadialog.costcalclist.row.cfalterationfee = data.costcalclist.cfalterationfee;
            this.basedatadialog.costcalclist.row.cffixedfee = data.costcalclist.cffixedfee;
            for (let i = 0; i < this.bomCalcdemandentryList.length; i++) {
              let treeData = this.bomCalcdemandentryList[i];
              if(treeData.cfboxunit == this.basedatadialog.costcalclist.row.cfboxunit){
                this.bomCalcdemandentryList[i] = this.basedatadialog.costcalclist.row;
              }
            }
            this.sumListAmount();
          }else{
            this.switchDataSource(this.basedatadialog.costcalclist.row);
          }
          break;
      }
    },
  }
};
</script>
